<template>
  <div>
    <ul>
      <li
        :class="isActive === index ? 'isActive' : ''"
        v-for="(item, index) in tagList"
        :key="index"
        @click="handleChangeClick(index, item)"
      >
        {{ item }}
      </li>
    </ul>
  </div>
</template>

<script>
export default {
  props: {
    tagList: {
      type: Array,
      default() {
        return [];
      },
    },
    state: {
      type: Number,
      default: -1,
    },
  },
  data() {
    return {
      isActive: -1,
    };
  },
  watch: {
    state(item) {
      this.isActive = item;
    },
  },

  methods: {
    handleChangeClick(index, item) {
      this.isActive = index;
      this.$emit("handleChangeClick", index, item);
    },
  },
};
</script>

<style lang='scss' scoped>
ul {
  display: flex;
  overflow: hidden;
}
li {
  position: relative;
  top: 10px;
  height: 40px;
  line-height: 30px;
  padding: 5px 10px;
  text-decoration: none;
  color: #ffffff;
  justify-content: space-around;
  background: #444;
  border-radius: 60%;
  transition: 0.5s;
}
.isActive {
  background: red;
}
li:hover {
  top: 0;
}
</style>